if exists (select * from sys.foreign_keys where name = 'fk_Nhanvien_phongban')
begin
	alter table NHANVIEN drop constraint fk_Nhanvien_phongban
end
go
--foreign key 1

alter table NHANVIEN 
add constraint fk_Nhanvien_phongban 
foreign key (PHG) 
references PHONGBAN(MAPHG)

--foreign key 2

alter table PHANCONG
add constraint fk_Nhanvien_Phancong
foreign key (MA_NVIEN)
references NHANVIEN(MANV)
--foreign key 3

alter table PHANCONG
add constraint fk_Phancong_dean
foreign key (MA_NVIEN)
references dean(MADA)
--foreign key 4
alter table THANNHAN
add constraint fk_nhanvien_thannhan
foreign key (TENTN)
references NHANVIEN(MANV)
--foreign key 5

alter table PHONGBAN
add constraint fk_phongban_DD_PHG
foreign key (TRPHG)
references DIADIEM_PHG(MAPHG)

--foreign key 6

alter table PHONGBAN
add constraint fk_Nhanvien_Phongban
foreign key (TRPHG)
references NHANVIEN(MANV)

	